#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <stdbool.h>

#define NUM_SUPPLY 10
void testSmithyEffect (void)
{
    struct gameState G;
    int k[NUM_SUPPLY] =
    {
        adventurer, gardens, embargo, village, minion, mine, cutpurse,
        sea_hag, tribute, smithy
    };
    
    initializeGame(2, k, 1, &G);
    
    int player = G.whoseTurn;
    
    int smithy_pos = G.handCount[player];
    
    if (gainCard (smithy, &G, 2, player) == -1)
    {
        printf ("%s: FAIL attempting to gain a smithy!\n", __func__);
        return;
    }
    else
    {
        printf ("%s: PASS attempting to gain a smithy.\n", __func__);
    }
    
    if (cardEffect (smithy, 0, 0, 0, &G, smithy_pos, NULL) == -1)
    {
        printf ("%s: FAIL attempting to play a smithy!\n", __func__);
        return;
    }
    else
    {
        printf ("%s: PASS attempting to play a smithy.\n", __func__);
    }
    
    if (G.handCount[player] == smithy_pos + 3)
    {
        printf ("%s: PASS verifying smithy drew 3 cards.\n", __func__);
    }
    else
    {
        printf ("%s: FAIL verifying smithy drew 3 cards (%d != 3!)\n", __func__, G.handCount[player] - smithy_pos);
        return;
    }
    
    for (int i = 0; i < G.handCount[player]; i++)
    {
        char *ordinals[3] = {"first", "second", "third"};
        int card = G.hand[player][i];
        if (card != copper && card != estate)
        {
            printf ("%s: FAIL verifying %s card drawn by smithy is valid (%d is not!)\n", __func__, ordinals[i-smithy_pos], card);
            return;
        }
    }
    
    printf ("%s: PASS verifying all cards drawn by smithy are valid.\n", __func__);
}

int main (int argc, char *argv[])
{
    testSmithyEffect ();
}
